package org.demo.base.jdbc.util;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.Connection;
import java.sql.SQLException;

public class TXQueryRunner extends QueryRunner{

    @Override
    public int[] batch(String sql, Object[][] params) throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        int[] result=super.batch(conn,sql,params);
        JDBCUtils.releaseConnection();
        return result;
    }

    @Override
    public <T> T query(String sql, Object param, ResultSetHandler<T> rsh)
            throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        T result=super.query(conn,sql,param,rsh);
        JDBCUtils.releaseConnection();
        return result;
    }

    @Override
    public <T> T query(String sql, Object[] params, ResultSetHandler<T> rsh)
            throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        T result=super.query(conn,sql,params,rsh);
        JDBCUtils.releaseConnection();
        return result;
    }

    @Override
    public <T> T query(String sql, ResultSetHandler<T> rsh, Object... params)
            throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        T result=super.query(conn,sql,rsh,params);
        JDBCUtils.releaseConnection();
        return result;
    }

    @Override
    public <T> T query(String sql, ResultSetHandler<T> rsh) throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        T result=super.query(conn,sql,rsh);
        JDBCUtils.releaseConnection();
        return result;
    }

    @Override
    public int update(String sql) throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        int result=super.update(conn,sql);
        return result;
    }

    @Override
    public int update(String sql, Object param) throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        int result=super.update(conn,sql);
        return result;
    }

    @Override
    public int update(String sql, Object... params) throws SQLException {
        Connection conn=JDBCUtils.getConnection();
        int result=super.update(conn,sql,params);
        return result;
    }


}
